<?php

/*
Scheduled Tasks (admin_tasks.pro.php)
*/

$page_title = "Scheduled Tasks";
$rank_check = 7;
include "../global.inc.php";
$game=$_GET['game'];
$act=$_GET['act'];
$task=$_GET['task'];


$task_type = $_POST['task_type'];
$task_hour = $_POST['task_hour'];
$task_minutes = $_POST['task_minutes'];
$am_pm = $_POST['am_pm'];
$monthly_run = $_POST['monthly_run'];
$weekly_run = $_POST['weekly_run'];
$add_update = $_POST['add_update'];


if ($act == "edit")
{
	if (($task_type != "Low Stock") AND 
	($task_type != "Medium Stock") AND 
	($task_type != "Full Stock") AND 
	($task_type != "Lower Pet Attitude") AND 
	($task_type != "Lower Pet Hunger") AND 
	($task_type != "Lower User Hunger") AND 
	($task_type != "End Penny Play") AND 
	($task_type != "End Referral Contest") AND 
	($task_type != "End Daily Lotto"))
	{ die("Please choose a valid task option."); }
	
	if (($task_hour < "0") OR ($task_hour > "12"))
	{
		die(header(error("admin_tasks.php?game=$game","Please choose a valid hour 0-12 for this task.")));
	}

	if (($task_minutes < "0") OR ($task_minutes > "59"))
	{
		die(header(error("admin_tasks.php?game=$game","Please choose a valid hour 0-59 for this task.")));
	}

	$task_hour += $am_pm;
	
	$check = strlen($task_hour);
	if ($check == "1") { $task_hour = "0$task_hour"; }
	$check = strlen($task_hour);
	if ($check != "2")
	{
		die(header(error("admin_tasks.php?game=$game","The hour specified must only be two characters.")));
	}
	
	$check = strlen($task_minutes);
	if ($check == "1") { $task_minutes = "0$task_minutes"; }
	$check = strlen($task_minutes);
	if ($check != "2")
	{
		die(header(error("admin_tasks.php?game=$game","The minute specified must only be two characters.")));
	}
	
	$cronTime = "$task_hour:$task_minutes";

	if (($monthly_run) AND (($monthly_run < "1") OR ($monthly_run > "31")))
	{
		die(header(error("admin_tasks.php?game=$game","The monthly run must be between 1 and 31.")));
	}
	if (($weekly_run) AND (($weekly_run < "1") OR ($weekly_run > "7")))
	{
		die(header(error("admin_tasks.php?game=$game","The weekly run must be between Sunday and Saturday.")));
	}
	
	if (($weekly_run) AND ($monthly_run))
	{
		die(header(error("admin_tasks.php?game=$game","You may only select a monthly run OR a weekly run, you cannot do both.")));
	}
	
	mysql_query("Update ghetto_cron set cron_name = '$task_type', cron_time = '$cronTime', monthly_run = '$monthly_run', weekly_run = '$weekly_run', add_update = '$add_update' where game = $game and id = $task") or die(mysql_error());

	die(header(error("admin_tasks.php?game=$game","Your task has been updated!")));
}

?>
